import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/SysPassworMan',
    name: 'SysPassworMan',
    component: () => import('@/views/permission/views/system-password/index'),
    meta: { title: 'SysPassworMan', icon: 'SysPassworMan' }
  },
  // 用户管理
  {
    path: '/userManagemenet',
    name: 'UserManagemenet',
    component: () => import('@/views/permission/views/user-management/index'),
    meta: { title: 'UserManagemenet', icon: 'UserManagemenet' }
  },
  // 资源管理
  {
    path: '/moulds-mangement/sys-resu-d',
    name: 'ResourceManagement',
    component: () => import('@/views/permission/views/resource-management/index'),
    meta: { title: 'ResourceManagement', icon: 'el-icon-document' }
  },
  // 子系统管理
  {
    path: '/subsys/sys-subsys-d',
    name: 'SubsysManagement',
    component: () => import('@/views/permission/views/subsystem-management/index'),
    meta: { title: 'SubsysManagement', icon: 'el-icon-document' }
  },
  // 安全角色管理
  {
    path: '/security-role-management',
    name: 'SecurityRoleManagement',
    component: () => import('@/views/permission/views/security-role-management/index'),
    meta: { title: 'SecurityRoleManagement', icon: 'el-icon-document' }
  },
  // 业务角色管理
  {
    path: '/busirole-management',
    name: 'BusiroleManagement',
    component: () => import('@/views/permission/views/busirole-management/index'),
    meta: { title: 'BusiroleManagement', icon: 'el-icon-document' }
  }, {
    path: '/organiz/sys-orgunt-d',
    name: 'sysOrguntD',
    component: () => import('@/views/permission/views/sys-orgunt-d/index'),
    meta: { title: 'sysOrguntD', icon: 'el-icon-document' }
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
